import { findIndex } from "lodash";
import { CpcBase, ICpcBaseIos } from "../base/CpcBase";
import { CpcDrawerCtrl, ICpcDrawerConfig } from "../../../../components/CpcDrawer/CpcDrawerCtrl";

const ios: ICpcBaseIos = {
    inputs: [],
    outputs: [
        {
            name: "outSource",
            type: "Object",
            label: "输入的对象",
        },
    ],
};

export class ToObject extends CpcBase {
    public title = "转为对象";

    public desc = "转为对象";

    public type = "ToObject";

    protected codeEditDbShow = true;

    protected codeEidtReadOnly = true;

    constructor(title?: string) {
        super(ios, title);
        this.addWidget("button", "编辑输入节点", "", this.clickAdd.bind(this));
    }

    clickAdd() {
        const self = this;
        CpcDrawerCtrl.open(
            {
                component: "AEBasicField",
                data: this.getInputsNot0(),
                callBack(data: any, close: any) {
                    self.updateInputsNot0(data);
                    close();
                },
            },
            {
                title: "编辑输入节点",
                styleType: "center",
                isMaskEvent: false,
            }
        );
    }

    cpcRunCode(preDatas: any[], inputInfos: any[], outputInfos: any[]): any[] {
        const result: any = {};
        inputInfos.forEach((item, index) => {
            result[item.name] = preDatas[index];
        });
        return [result];
    }
}
